module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
	$scope.pageInfo = {
		'pageNo': 1,
		'pageSize': 10,
		'totalItems': 0
	};

	//获取消息推送列表
	$scope.loadlist = function () {
		$resource('/api/as/mc/pushinfo/findList', {}, {}).save($scope.pageInfo, function(res){
			if (res.errcode === 0) {
				$scope.beanList = res.data.results;
				$scope.pageInfo.totalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}
	$scope.loadlist();

	//消息详情
	$scope.info = function (bean) {
		var modalInstance = $modal.open({
			template: require('../views/pushinfoinfo.html'),
			controller: 'pushinfoinfo',
			size: 'lg',
			resolve: {
				bean: function () {
					return bean;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
			$scope.loadlist();
		});
	}

	//发送
    $scope.send = function (bean) {
		$resource('/api/as/mc/pushinfo/updatesend', {}, {}).save(bean, function (res) {
			if (res.errcode === 0) {
				$scope.loadlist();
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

	//删除
	$scope.delete = function (bean) {
		if (confirm('确认删除此条记录吗？') == true) {
			$resource('/api/as/mc/pushinfo/updatedel', {}, {}).save(bean, function (res) {
				if (res.errcode === 0) {
					$scope.loadlist();
				} else {
					toaster.error({ title: '', body: res.errmsg });
				}
			});
		}
	}

};